//% color="#6A5ACD" iconWidth=50 iconHeight=40
namespace LCD1602RGB{
    //% block="LCD1602RGB init[VER] " blockType="command" 
    //% VER.shadow="dropdown"  VER.options="VER"
    export function LCD1602RGBInit(parameter: any, block: any) {
        let ver=parameter.VER.code;
        Generator.addInclude("LCD1602RGBInit", "#include <Wire.h>");
        if (ver=="1"){
        Generator.addInclude("LCD1602RGBInit1", "#include <DFRobot_LCD.h>");
        Generator.addObject(`LCD1602RGBInit`,  "DFRobot_RGBLCD1602"," lcd(16,2);");
        }
        if (ver=="2"){
        Generator.addInclude("LCD1602RGBInit1", "#include <DFRobot_RGBLCD1602.h>");
        Generator.addObject(`LCD1602RGBInit`,  "DFRobot_RGBLCD1602"," lcd(0x2D,16,2);");
        }
       // Generator.addSetup(`LCD1602RGBInit`,  "Serial.begin(9600);");
        Generator.addSetup(`LCD1602RGBInit1`, "lcd.init();");

    }
      //% block="LCD1602RGB Dir[LR]  " blockType="command" 
      //% LR.shadow="dropdown"  LR.options="LR"
      export function LCD1602RGBInitLR(parameter: any, block: any) {
        let lr=parameter.LR.code; 
    
        Generator.addCode(`lcd.scrollDisplay${lr}();`);
     
    }
    //% block="LCD1602RGB setColor R [R]G [G]B [B] " blockType="command" 
    //% R.shadow="range" R.params.min="0"  R.params.max="255" R.defl="100"
    //% G.shadow="range" G.params.min="0"  G.params.max="255" G.defl="100"
    //% B.shadow="range" B.params.min="0"  B.params.max="255" B.defl="100"
    export function LCD1602RGBInitset(parameter: any, block: any) {

        let r=parameter.R.code;
        let g=parameter.G.code;  
        let b=parameter.B.code;  
        
        
        Generator.addCode(`lcd.setRGB(${r},${g},${b});`);
        

    } 
    //% block="LCD1602RGB Print Line [Y] Mess [SR]  " blockType="command" 
    //% Y.shadow="dropdown" Y.options="Y" 
    //% SR.shadow="string"  SR.defl="DFRobot hello"
    export function LCD1602RGBInitprintline(parameter: any, block: any) {
       
       let y=parameter.Y.code;  
       let sr=parameter.SR.code;  
 
       Generator.addCode(`lcd.setCursor(0,${y});`);
       Generator.addCode(`lcd.print(${sr});`);

   }
    
     //% block="LCD1602RGB Print X [X]Y [Y]Mess [SR]  " blockType="command" 
     //% X.shadow="number" X.params.min="0"  X.params.max="16" X.defl="0"
     //% Y.shadow="number" Y.params.min="0"  Y.params.max="1" Y.defl="0"
     //% SR.shadow="string"  SR.defl="DFRobot hello"
     export function LCD1602RGBInitprint(parameter: any, block: any) {
        let x=parameter.X.code;
        let y=parameter.Y.code;  
        let sr=parameter.SR.code;  
        Generator.addCode(`lcd.setCursor(${x},${y});`);
        Generator.addCode(`lcd.print(${sr});`);

    }
   
     
    //% block="LCD1602RGB Clear  " blockType="command" 
    
    export function LCD1602RGBInitclear(parameter: any, block: any) {
        
        Generator.addCode("lcd.clear();");
        

    }
}
